/**
 * Created by JetBrains WebStorm.
 * User: nhuang
 * Date: 12-3-30
 * Time: 下午3:24
 * To change this template use File | Settings | File Templates.
 */
(function($){
    $.fn.myTabs=function(options){
        var defaults={
            tabsTitleClass:'tabNor',
            tabsTitleCurClass:'selected',
            tabsEvent:'click',
            contentClass:'tabsContent',
//            contentCurClass:'cur',
            autoStyle:'fadeIn',
            fadeTime:500,
            autoPlay:true,
            delayTime:1000,
            clearAutoEvent:'mouseover'
        };
        var opts=$.extend(defaults,options);

        this.each(function(){
            var thisTabs=$(this);
            thisTabs.find('.'+opts.tabsTitleClass).bind(opts.tabsEvent,function(){
                var index= $(this).index();
                $(this).addClass(opts.tabsTitleCurClass).siblings().removeClass(opts.tabsTitleCurClass);
                thisTabs.find('.'+opts.contentClass).eq(index)[opts.autoStyle](opts.fadeTime).siblings().hide()
                });

            if(opts.autoPlay){
                thisTabs.find('.'+opts.tabsTitleClass).bind(opts.clearAutoEvent,function(){
                    this.clearTimeout(autoTime)
                });
                var autoTime=setInterval(function(){
                    myTime()
                },opts.delayTime)
            }

            function myTime(){
                var i;
                var len=$('.'+opts.tabsTitleClass).length;
                for(i=0;i<len;i++){
                    thisTabs.find('.'+opts.tabsTitleClass).eq(i)[opts.tabsEvent]();
                    if(i==len) i=0;
                }
            }
        });
    }
})(jQuery);
